<div class="modal" ng-controller="FlowableDecisionTableReferencePopupCtrl">
  <div class="modal-dialog modal-wide">
    <div class="modal-content">
      <div class="modal-header" ng-if="popup.state == 'decisionTableReference'">
        <button aria-hidden="true" class="close" data-dismiss="modal" ng-click="close()" type="button">&times;</button>
        <h2>
          {{'PROPERTY.DECISIONTABLEREFERENCE.TITLE' | translate}}
          <span ng-show="selectedDecisionTable != null"> - {{selectedDecisionTable.name}}</span>
          <span ng-show="selectedDecisionTable == null"> - {{'PROPERTY.DECISIONTABLEREFERENCE.EMPTY' | translate}}</span>

        </h2>
      </div>
      <div class="modal-header" ng-if="popup.state == 'newDecisionTable'"><h2>{{'DECISION-TABLE.POPUP.CREATE-TITLE' |
        translate}}</h2></div>
      <div class="modal-body-with-overflow" ng-if="popup.state == 'decisionTableReference'">
        <div class="detail-group clearfix">
          <div class="col-xs-12">
            <div class="alert alert-error" ng-show="!state.loadingDecisionTables && state.decisionTableError" translate>
              PROPERTY.DECISIONTABLEREFERENCE.ERROR.FORM
            </div>
          </div>
        </div>
        <div class="detail-group clearfix">
          <div class="col-xs-12 editor-item-picker">
            <div class="col-xs-4 editor-item-picker-component"
                 ng-class="{'selected' : decisionTable.decisionTableId == selectedDecisionTable.decisionTableId}"
                 ng-click="selectDecisionTable(decisionTable, $event)"
                 ng-if="!state.loadingDecisionTables && !state.decisionTableError"
                 ng-repeat="decisionTable in decisionTables">
              <div class="controls">
                <input ng-checked="decisionTable.id == selectedDecisionTable.id"
                       ng-click="selectDecisionTable(decisionTable, $event)" type="checkbox"
                       value="option1"/>
              </div>
              <h4>{{decisionTable.name}}</h4>
              <img ng-src="{{getModelThumbnailUrl(decisionTable.id)}}"/>
            </div>
            <div ng-show="state.loadingDecisionTables">
              <p class="loading" translate>PROPERTY.DECISIONTABLEREFERENCE.DECISIONTABLE.LOADING</p>
            </div>
            <div ng-show="!state.loadingDecisionTables && decisionTables.length == 0">
              <p translate>PROPERTY.DECISIONTABLEREFERENCE.DECISIONTABLE.EMPTY</p>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-body" ng-if="popup.state == 'newDecisionTable'">
        <p>{{'DECISION-TABLE.POPUP.CREATE-DESCRIPTION' | translate}}</p>
        <div class="alert error" ng-if="model.errorMessage && model.errorMessage.length > 0"
             style="font-size: 14px; margin-top:20px">
          <div class="popup-error" style="font-size: 14px">
            <span class="glyphicon glyphicon-remove-circle"></span>
            <span>{{model.errorMessage}}</span>
          </div>
        </div>
        <div class="form-group">
          <label for="newDecisionTableName">{{'DECISION-TABLE.NAME' | translate}}</label>
          <input auto-focus class="form-control" custom-keys
                 editor-input-check enter-pressed="ok()" id="newDecisionTableName" ng-disabled="model.loading"
                 ng-model="model.decisionTable.name" type="text">
        </div>
        <div class="form-group">
          <label for="newDecisionTableKey">{{'DECISION-TABLE.KEY' | translate}}</label>
          <input class="form-control" editor-input-check id="newDecisionTableKey"
                 ng-disabled="model.loading" ng-model="model.decisionTable.key" type="text">
        </div>
        <div class="form-group">
          <label for="newDecisionTableDescription">{{'DECISION-TABLE.DESCRIPTION' | translate}}</label>
          <textarea class="form-control" id="newDecisionTableDescription" ng-disabled="model.loading"
                    ng-model="model.decisionTable.description"
                    rows="5"></textarea>
        </div>
      </div>
      <div class="modal-footer" ng-if="popup.state == 'decisionTableReference'">
        <button class="btn btn-primary" ng-click="cancel()" translate>GENERAL.ACTION.CANCEL</button>
        <button class="btn btn-primary" ng-click="newDecisionTable()" ng-disabled="state.decisionTableError" translate>
          GENERAL.ACTION.NEW-DECISION-TABLE
        </button>
        <button class="btn btn-primary" ng-click="open()"
                ng-disabled="!selectedDecisionTable || state.decisionTableError" translate>GENERAL.ACTION.OPEN
        </button>
        <button class="btn btn-primary" ng-click="save()" ng-disabled="state.decisionTableError" translate>
          GENERAL.ACTION.SAVE
        </button>
      </div>
      <div class="modal-footer" ng-if="popup.state == 'newDecisionTable'">
        <button class="btn btn-primary" ng-click="cancel()" translate>GENERAL.ACTION.CANCEL</button>
        <button class="btn btn-primary"
                ng-click="createDecisionTable()"
                ng-disabled="state.decisionTableError || model.decisionTable.name.length == 0 || model.decisionTable.key.length == 0"
                translate>GENERAL.ACTION.CREATE-DECISION-TABLE
        </button>
      </div>
    </div>
  </div>
</div>
